<template>
  <!--推荐的上架商品-->
  <div class="recom">
    <div class="categoryName">我的收藏</div>
    <!--显示搜索到的景区-->
    <div class="py-12 bg-gray-50">
      <div class="max-w-7xl mx-auto px-4">
        <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
          <div v-for="collect in pageInfo.list"
               :key="collect.scenicSpot.id" class="bg-white rounded-lg shadow-sm overflow-hidden hover:shadow-md transition-shadow"
               @click="toScenicSpotView(collect.scenicSpot.id)">
            <div class="relative">
              <img :src="SERVER_ADDR + '/scenicSpot/pic/' + collect.scenicSpot.picList[0].url" :alt="collect.scenicSpot.name" class="w-full h-48 object-cover object-top">
              <button class="!rounded-button absolute top-4 right-4 w-8 h-8 bg-white/80 flex items-center justify-center" @click="toggleFavorite(collect.scenicSpot)">
                <el-icon :class="collect.scenicSpot.isFavorite ? 'text-red-500' : 'text-gray-600'"><Star /></el-icon>
              </button>
            </div>
            <div class="p-4">
              <h3 class="text-lg font-medium mb-2">{{ collect.scenicSpot.name }}</h3>
              <p class="text-sm text-gray-600 mb-4">{{ collect.scenicSpot.description }}</p>
              <div class="flex items-center justify-between">
                <div>
                  <span class="text-red-600 text-lg font-bold">¥{{ Number(collect.scenicSpot.ticketPrice * 0.5).toFixed(2)}}</span>
                  <span class="text-gray-400 text-sm">/人起</span>
                </div>
                <div class="flex items-center">
                  <el-icon class="text-yellow-400 mr-1"><Clock /></el-icon>
                  <span class="text-sm text-gray-600">{{ collect.scenicSpot.recommendDuration }}</span>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
  <div class="collectNav">
    <el-row justify="center">
      <el-pagination background layout="prev, pager, next"
                     :page-count="pageInfo.pages"
                     @update:current-page="getUserCollects"
                     style="margin-top: 10px; text-align: center"
                     v-model:current-page="pageInfo.pageNum" />
    </el-row>

  </div>
</template>

<script setup>
import collectApi from "@/api/collectApi.js";
import {ref} from "vue";
import {useRouter} from "vue-router";

//服务器的地址
const SERVER_ADDR = ref(import.meta.env.VITE_SERVER_ADDR)
const pageInfo = ref({});
const router = useRouter();
const getUserCollects = (pageNum) => {
  collectApi.select(pageNum,5 )
      .then(resp => {
        if (resp.code == 10000) {
          pageInfo.value = resp.data;
        }
      })
}
//跳转到商品详情页面
const toScenicSpotView = (id)=>{
  router.push({
    path: '/user/scenicSpot',
    query: {
      id
    }
  });

}
getUserCollects(1);
</script>

<style scoped>
.ad {
  margin: 20px 0;
}
.ad ul li {
  float: left;
  width: 285px;
  margin-right: 20px;
}
.ad ul li:last-child{
  margin-right: 0px;
}
.recom .goodsList ul li {
  width: 224px;
  float: left;
  margin-right: 20px;
  margin-bottom: 15px;
  text-align: center;
  background-color: #fff;
  cursor: pointer;
}
.recom .goodsList ul li:hover{
  box-shadow: 0px 0px 20px #000;
}
.recom .goodsList ul li:nth-child(5n) {
  margin-right: 0px;
}

.recom {
  margin-bottom: 20px;
}

.recom .categoryName {
  font-size: 20px;
  margin-bottom: 5px;
  font-weight: bold;
}
.name, .dscp, .price{
  line-height: 25px;
}
.recom .name {
  font-size: 16px;
  font-weight: bold;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.recom .dscp {
  color: #aaa;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.recom .price {
  font-size: 12px;
  color:  var(--theme-color);
}
.collectNav {
  padding: 10px;
  background-color: #ffffff;
}
</style>